<?php

namespace App\Http\Middleware;

use Closure;

/*解密 base64 字符串 */
class StrDecode
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $arr = $request->all();
        foreach ($arr as $k => $value) {
            if(!strstr($k,'password') || !$k=='repass'){
                continue;
            }
            if($value == base64_encode(base64_decode($value))){
                $request->offsetSet($k, base64_decode($value));
            }
        }
        //继续后续的请求
        return $next($request);
    }
}
